﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLite;
using CSScriptLibrary;

namespace MOJsdk
{
    public class LogicStatment
    {
        public LogicStatment()
        {
            Name = "";
            Code = "";
            Librarys = "";
        }

        [PrimaryKey, Unique]
        public string Name { get; set; }
        public string Code { get; set; }
        public string Librarys { get; set; }

        public string BuildClass(string vars)
        {
            string myVars = "IHost HOST = MojHost.GetHost;\n" + vars + ";";
            string myClass = "public class myClass\n{\npublic bool Evaluate()\n{\n" +
                myVars + "\nreturn " + Code + ";\n}\npublic object elem { get; set; }\n}";
            return BuildLibrarys() + "\n" + myClass;
        }
        private string BuildLibrarys()
        {
            string libs = "using System;\nusing MOJsdk;";

            foreach (var v in Librarys.ToList(";"))
                libs += string.Format("\nusing {0};", v);

            return libs;
        }
    }

    public interface LogicalElement
    {
        object elem { get; set; }
        bool Evaluate();
    }
    public interface LogicalClass
    {
        bool TestStatment(LogicStatment statment);
    }
}
